$(function () {
    var url='../userGroupPurchase/list'
    $("#jqGrid").Grid({
        url: url,
        datatype: "json",
        height: '400',
        // mtype:'POST',

        colModel: [
            {label: '团购编号', name: 'userGroupPurchaseSn', index: 'userGroupPurchaseSn',
                cellattr: function(rowId, tv, rawObject, cm, rdata) {
                    return 'id=\'userGroupPurchaseSn' + rowId + "\'";
                }
            },
            {label: '拼团发起人', name: 'promoterName', index: 'nickName'},
            {label: '拼团标题', name: 'groupPurchaseEntity.title', index: 'groupPurchaseEntity.title'
            },
            {label: '参与拼团人数', name: 'groupPurchaseEntity.personNumber', index: 'groupPurchaseEntity.personNumber'},
            {label: '参与用户', name: 'participantName', index: 'participantName'},
            {label: '是否为机器人', name: 'robot', index: 'robot',align:"center",formatter: function (value){
                if(value==1){
                    return  '<span class="label  label-success">否</span>'
                }else{
                    return '<span class="label label-danger">是</span>';
                }
            }},
            // {label: '兑换码', name: 'exchangeCodeEntity.exchangeCode', index: 'exchangeCodeEntity.exchangeCode'},
            {label: '发起时间', name: 'createTime', index: 'createTime',formatter: function (value){
                    var time = new Date(value);
                    var y = time.getFullYear();
                    var m = time.getMonth()+1;
                    var d = time.getDate();
                    var h = time.getHours();
                    var mm = time.getMinutes();
                    var s = time.getSeconds();
                    var add0=function (m) {
                        return m<10?'0'+m:m
                    }
                    return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
                }},
            {label: '结束时间', name: 'endTime', index: 'endTime',formatter: function (value){
                    var time = new Date(value);
                    var y = time.getFullYear();
                    var m = time.getMonth()+1;
                    var d = time.getDate();
                    var h = time.getHours();
                    var mm = time.getMinutes();
                    var s = time.getSeconds();
                    var add0=function (m) {
                        return m<10?'0'+m:m
                    }
                    return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
                }},
            {
                label: '拼团状态', name: 'endTime', index: 'endTime', width: 80,align:"center", formatter: function (value) {
                    var time=Date.parse(new Date());
                    //debugger
                    if(value<time){
                        return  '<span class="label  label-success">拼团结束</span>'
                    }else {
                        return '<span class="label label-danger">进行中</span>';
                    }
                }
            }
            // {label: '分享时间', name: 'createTime', index: 'createTime'},
        ],
        gridComplete: function() {
            //②在gridComplete调用合并方法
            var gridName = "jqGrid";
            Merger(gridName, 'userGroupPurchaseSn');

        }
    });
    //公共调用方法
    function Merger(gridName, CellName) {
        //得到显示到界面的id集合
        var mya = $("#" + gridName + "").getDataIDs();
        //当前显示多少条
        var length = mya.length;
        for (var i = 0; i < length; i++) {
            //从上到下获取一条信息
            var before = $("#" + gridName + "").jqGrid('getRowData', mya[i]);
            //定义合并行数
            var rowSpanTaxCount = 1;
            for (j = i + 1; j <= length; j++) {
                //和上边的信息对比 如果值一样就合并行数+1 然后设置rowspan 让当前单元格隐藏
                var end = $("#" + gridName + "").jqGrid('getRowData', mya[j]);
                if (before[CellName] == end[CellName]) {
                    rowSpanTaxCount++;
                    $("#" + gridName + "").setCell(mya[j], CellName, '', { display: 'none' });
                } else {
                    rowSpanTaxCount = 1;
                    break;
                }
                $("#" + CellName + "" + mya[i] + "").attr("rowspan", rowSpanTaxCount);
            }
        }
    }
});

let vm = new Vue({
    el: '#rrapp',
    data: {
        q: {
            param:'', //拼团发起人
            num:'', //团购编号
        },
        listDataShow:true,

    },
    methods: {
        listExport() {
            exportFile('#rrapp', '../userExchange/export',{parentId:''});
        },
        query(){
            vm.reload()
            // this.listDataShow=false
        },
        reload(){
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            // console.log(page);
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {
                    'keywords': vm.q.nickName
                },
                page: page
            }).trigger("reloadGrid");
        }
    },
    created: function () {

    }
});